import Router from 'koa-router' // 引入路由中间件
import axios from './utils/axios' // 引入axios

// 定义路由前缀
const router = new Router({
  prefix: '/categroy'
})

// 面包屑接口categroy/crumbs
router.get('/crumbs', async (ctx) => {
  // 此接口目前已无法请求
  const { status, data: { areas, types } } = await axios.get('http://cp-tools.cn/crumbs', {
    params: {
      city: ctx.query.city.replace('市', '') || '北京'
    }
  })
  ctx.body = {
    areas: status === 200 ? areas : [],
    types: status === 200 ? types : []
  }
})

export default router
